<template>
  <div class="text-input">
    <div class="input-group" :class="[error?'is-invalid': '']">
      <!-- 输入框 -->
      <input :type="type" :name="name" :placeholder="placeholder" @input="$emit('input',$event.target.value)">

      <!-- 输入框后面的按钮 -->
      <button v-if="btnTitle" :disabled="disabled" @click="$emit('btnClick')">{{ btnTitle }}</button>
    </div>
    <!-- 错误提醒 -->
    <div class="invalid-feedback" v-if="error">{{ error }}</div>
  </div>
</template>

<script>
export default {
  name: 'MyTextInput',
  props: {
    type: {
      type: String,
      default: ''
    },
    value: String,
    placeholder: String,
    name: String,
    // 控制按钮文本
    btnTitle: String,
    disabled: Boolean,
    // 控制验证码对于错  进行提示
    error: String
  }
}
</script>

<style lang="less" scoped>
.input-group {
  display: flex;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  justify-content: space-between;
  align-items: center;
  input {
    height: 100%;
    width: 60%;
    outline: none;
    border: none;
  }
  button {
    height: 100%;
    border: none;
    outline: none;
    color: #333;
    background-color: #fff;
    font-size: 14px;
  }
}
.input-group button[disabled] {
  color: #aaa;
}
.is-invalid {
  border: 1px solid red;
}
.invalid-feedback {
  display: flex;
  flex-direction: row;
  color: red;
  padding-top: 5px;
}
</style>
